<?php
$class_map = array();

function getClassInterface($source_file) {
	$source = file_get_contents($source_file);
	$tokens = token_get_all($source);
	global $class_map;
	for ($i = 0; $i < count($tokens); $i ++) {
		$token = $tokens[$i][0];
		if ($token === T_INTERFACE || $token === T_CLASS) {
			for ( ; ; $i ++) {
				if ($tokens[$i][0] === T_STRING) {
					$class_map[strtolower($tokens[$i][1])] = substr($source_file, 3);
					break;
				}
			}
		}
	}
}

function enumSourceFiles($path) {
	$dir = dir($path);
	while (false !== ($entry = $dir->read())) {
		if ('.' === $entry[0]) continue;
		$entry_full_path = $path.'/'.$entry;
		if (is_dir($entry_full_path)) {
			enumSourceFiles($entry_full_path);
		} else {
			getClassInterface($entry_full_path);
		}
	}
	$dir->close();
}

enumSourceFiles('..');
file_put_contents('../res/class.dat', serialize($class_map));

